<template>
	<view class="">
		<u-navbar :is-back="false" title="TOU透氧教练端" :background="background" title-color="#ffffff;"></u-navbar>
		<view class="index-nav">
			<image class="index-nav-bg" src="https://image.nanjingtouyang.com/touy/2024/05/08/a0eb816a3ba04976b5e885a0cafbbf85.png" mode=""></image>
		</view>
		
		<view class="my-box">
			<!-- 头像 -->
			<view class="">
				<view v-if="isLogin == 1" class="my-head-box">
					<view class="head-box-item">
						<image v-if="spInfo.spAvatar" class="head-image" :src="spInfo.spAvatar"></image>
						<image v-else class="head-image" src="https://image.nanjingtouyang.com/touy/2024/05/20/b528001914de4cfd8d6a619a413b3f16.png" mode=""></image>
						<image v-if="spInfo.sex == 1" class="user-sex-icon" src="https://image.nanjingtouyang.com/touy/2024/02/21/07e48f057c924ddfb9d72ce5d5bc61b0.png" mode=""></image>
						<image v-else class="user-sex-icon" src="https://image.nanjingtouyang.com/touy/2024/02/21/d8ec51ceecc34ac19cfbdd7841b881cb.png" mode=""></image>
					</view>
				</view>
				<view v-else class="my-head-box">
					<view class="head-box-item">
						<image class="head-image" src="https://image.nanjingtouyang.com/touy/2024/05/20/b528001914de4cfd8d6a619a413b3f16.png" mode=""></image>	
					</view>
				</view>
			</view>
			
			
			<!-- 信息 -->
			<view class="">
				<view v-if="isLogin == 1" class="info-box">
					<view class="info-box-user">
						
						<view v-if="isCoach == 0">
							<view class="info-box-title" v-show="spInfo.spName !== null">
								<view class="title-name" v-show="spInfo.spName !== null">{{ spInfo.spName }}</view>
							</view>
							<view v-if="status == '03'" class="info-button" @click="toExamine(2)">
								申请未通过
							</view>
							<view v-else-if="status == '01'" class="info-button" @click="toExamine(1)">
								平台审核中
							</view>
							<view v-else class="info-button" @click="toAuth">
								申请入驻成为教练
							</view>
						</view>
						
						
						<view v-else>
							<view class="info-box-title" @click="toEditInfo()">
								<view class="title-name">{{ spInfo.spName }}</view>
								<image class="set-icon" src="https://image.nanjingtouyang.com/touy/2024/05/15/76c8149bd8d74f6ca68ad4095479c390.png" mode=""></image>
							</view>
							<view class="info-box-texts">{{ spInfo.age }}岁｜从业{{ spInfo.workYears }}年｜已认证</view>
							<view class="info-box-brief">{{ spInfo.spDesc }}</view>
						</view>
						
						<view class="info-tabs">
							<view class="info-tabs-item">
								<view v-if="isCoach == 1" class="item-num">{{ spInfo.ordCount }}</view>
								<view v-else class="item-num">0</view>
								<view class="item-text">接单量</view>
								<image class="item-line" src="https://image.nanjingtouyang.com/touy/2024/05/15/150e9986c07749738e28f495705fc23b.png" mode=""></image>
							</view>
							<view class="info-tabs-item">
								<view v-if="isCoach == 1" class="item-num">
									<text v-if="spInfo.evalScore">{{ spInfo.evalScore }}</text>
									<text v-else>0</text>
								</view>
								<view v-else class="item-num">0</view>
								<view class="item-text">我的评分</view>
								<image class="item-line" src="https://image.nanjingtouyang.com/touy/2024/05/15/150e9986c07749738e28f495705fc23b.png" mode=""></image>
							</view>
							<view class="info-tabs-item">
								<view v-if="isCoach == 1" class="item-num">
									<text v-if="spInfo.balance">{{ spInfo.balance }}</text>
									<text v-else>0</text>
								</view>
								<view v-else class="item-num">0</view>
								<view class="item-text">总收益（元）</view>
							</view>
						</view>
						
					</view>
					<view class="info-line-box"></view>
				</view>
				
				<view v-else class="info-box">
					<view class="info-box-user">
						<view class="info-button" @click="toLogin">
							立即登录
						</view>
					</view>
					
				</view>
			</view>
			
			
			<!-- 功能 -->
			<view class="function-box">
				<view class="function-box-title">
					常用功能
				</view>
				<view class="function-box-view">
					<view class="view-item" v-for="(item, index) in tabList" :key="index" @click="toTabBox(item)">
						<image class="item-icon-img" :src="item.icon"></image>
						<view class="item-icon-text">{{ item.name }}</view>
					</view>
				</view>
			</view>
			<view class="info-line-box"></view>
			
			<!-- 预约流程 -->
			<view class="tags-line">
				<view class="tags-title">
					<view class="title">预约流程</view>
					<image @click="openCover" class="title-icon" src="https://image.nanjingtouyang.com/touy/2024/05/15/69200f5dc80c4144bac49e4e8a7de040.png"></image>
				</view>
				<view class="tags-line-view">
					<scroll-view class="choose-scroll" scroll-x="true">
						<view class="choose-line"></view>
						<view 
							v-for="(item, index) in coachList"
							:key="index"
							class="choose-item"
							>
							<image class="choose-icon" src="https://image.nanjingtouyang.com/touy/2024/05/07/dfdfe1a3d0f94becb58e4304eede3010.png" mode=""></image>
							<view class="choose-text">
								{{ item.name }}
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
			
			
			<u-popup class="cover-box" v-model="coverShow" mode="center" border-radius="30">
				<view class="content-box">
					<rich-text :nodes="aptDesc"></rich-text>
				</view>
				<view class="confrim-btn" @click="closeCover">我知道了</view>
			</u-popup>
			
			<u-modal v-model="chooseWeekShow"
				@confirm="toChooseWeek" 
				@cancel="closeWeekShow"
				ref="uModal" 
				show-cancel-button="true" 
				show-title="false"
				cancel-text="取消" cancel-color="#333333"
				confirm-text="去设置" confirm-color="#46973B"
				borderRadius="35"
				>
				<view class="slot-content">
					<view class="content-title-text">温馨提示</view>
					<view class="content-title">
						系统检测到您尚未设置排班，请在<span style="color: #46973B;">“我的排班”</span>中进行设置
					</view>
				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
	import { getConfigKey } from "@/api/public.js"
	import { getMySpInfo } from '@/api/mine.js'
	export default {
		data() {
			return {
				tabList: [
					{
						id: 1,
						name: '教练核销',
						icon: 'https://image.nanjingtouyang.com/touy/2024/05/15/574753524c084fe293c4d61038c9848c.png',
						to: '../../pages/check-code/index'
					},
					{
						id: 2,
						name: '我的评价',
						icon: 'https://image.nanjingtouyang.com/touy/2024/05/15/5470d28b20c244f6af6356d72c2f5690.png',
						to: '../../pages/eval-list/index'
					},
					{
						id: 3,
						name: '我的钱包',
						icon: 'https://image.nanjingtouyang.com/touy/2024/05/15/ba2f74684ef64cdd9cc28bb3d330f6d4.png',
						to: '../../pages/my-wallet/index'
					},
					{
						id: 4,
						name: '联系客服',
						icon: 'https://image.nanjingtouyang.com/touy/2024/05/15/204c14bde21a4f4bb61b00558e3274b0.png'
					},
					{
						id: 6,
						name: '我的排班',
						icon: 'https://image.nanjingtouyang.com/touy/2024/07/15/e3706dc6cfb44c1aaf74418e876502a8.png',
						to: '../../pages/my-set/index'
					},
					{
						id: 5,
						name: '用户端',
						icon: 'https://image.nanjingtouyang.com/touy/2024/05/15/4dac3e6e7e514675b50fec2e33748ed1.png'
					}
				],
				coachList: [
					{ id: 1, name: '用户预约'},
					{ id: 2, name: '用户报名'},
					// { id: 3, name: '报名人付款'},
					{ id: 4, name: '教练接单'},
					// { id: 5, name: '场馆接单'},
					{ id: 6, name: '订单核销'},
					// { id: 7, name: '场馆核销'},
					{ id: 8, name: '开始训练'},
				],
				coverShow: false,
				isLogin: '',
				isCoach: '',
				servicePhone: '',
				status: '',
				spInfo: '',
				
				aptDesc: '',
				
				chooseWeekShow: false
			}
		},
		onLoad() {
			this.getServicePhone()
		},
		onShow() {
			if(uni.getStorageSync('spToken')) {
				this.isLogin = 1
				this.getSpInfo()
			} else {
				this.isLogin = 0
			}
		},
		methods: {
			toChooseWeek() {
				uni.navigateTo({
					url:'../../pages/my-set/index'
				})
			},
			closeWeekShow() {
				this.chooseWeekShow = true
			},
			getSpInfo() {
				getMySpInfo().then(res => {
					if(res.data.data.status == '02') {
						this.isCoach = 1
						
					}else {
						this.isCoach = 0
					}
					this.spInfo = res.data.data
					this.status = res.data.data.status
					if(res.data.data.isPromptSpWork == 1) {
						this.chooseWeekShow = true
					} else {
						this.chooseWeekShow = false
					}
				})
			},
			toExamine(type) {
				uni.navigateTo({
					url:'../../pages/examine-result/index?type='+type + '&reason=' + this.spInfo.statusReason
				})
			},
			toEditInfo() {
				uni.navigateTo({
					url:'../../pages/set-detail/index?isEdit=true'
				})
			},
			getServicePhone() {
				getConfigKey('plat_service_phone').then(res => {
					this.servicePhone = res.data.data
				})
				
				getConfigKey('t_apt_desc').then(res => {
					this.aptDesc = res.data.data
				})
			},
			toLogin() {
				uni.navigateTo({
					url:'../../pages/login/index'
				})
			},
			openCover() {
				this.coverShow = true
			},
			closeCover() {
				this.coverShow = false
			},
			toTabBox(item) {
				if(item.id == 5) {
					uni.navigateToMiniProgram({
						appId:'wx80fa62fb12d01fbf'
					})
				} else if(item.id == 4){
					uni.makePhoneCall({
						phoneNumber: this.servicePhone,
					})
				}else {
					if(this.isLogin == 1) {
						if(this.isCoach == 1) {
							uni.navigateTo({
								url:item.to
							})
						} else {
							uni.showToast({
								icon:'none',
								title:'请先申请入驻成为教练'
							})
						}
						
					} else {
						uni.navigateTo({
							url:'../../pages/login/index'
						})
					}
				}
				
				
				
			},
			toAuth() {
				// uni.navigateTo({
				// 	url:'../../pages/auth-detail/index'
				// })
				uni.navigateTo({
					url:'../../pages/choose-type/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './my.scss';
</style>
